﻿using System;
using System.Runtime.Serialization;
using SKBKontur.Serialization.Binding;

namespace SKBKontur.Logging.Model
{
    [DataContract]
    public class LogException
    {
        public override string ToString()
        {
            return string.Format("StackTrace: {0}, Type: {1}, Source: {2}, Message: {3}", StackTrace, Type, Source, Message);
        }

        public LogException()
        {
        }

        public LogException(Exception exception)
        {
            // todo Мало последнего эксепшна. Нужна вся цепочка по exception.InnerException
            Message = exception.Message;
            StackTrace = exception.StackTrace;
            Source = exception.Source;
            Type = exception.GetType().FullName;
        }

        [DataMember]
        [Utf8StringBinder]
        public string StackTrace { get; set; }

        [DataMember]
        [Utf8StringBinder]
        public string Type { get; set; }

        [DataMember]
        [Utf8StringBinder]
        public string Source { get; set; }

        [DataMember]
        [Utf8StringBinder]
        public string Message { get; set; }
    }
}